package com.training.web.controller;

import com.training.base.Result;
import com.training.bean.Feedback;
import com.training.base.ResponseUtils;
import com.training.web.service.WebFeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/web/feedback")
public class WebFeedbackController {

    @Autowired
    private WebFeedbackService service;
    
    @Autowired
    private ResponseUtils responseUtils;

    /**
     * 获取所有意见反馈
     * @return 意见反馈列表
     */
    @GetMapping("/getAll")
    public ResponseEntity<Result<List<Feedback>>> getAllFeedback() {
        try {
            List<Feedback> feedbackList = service.getAllFeedback();
            return responseUtils.success(feedbackList, "获取意见反馈列表成功");
        } catch (Exception e) {
            return responseUtils.failWithType(500, "获取意见反馈列表失败：" + e.getMessage());
        }
    }

    /**
     * 删除意见反馈
     * @param id 意见反馈ID
     * @return 操作结果
     */
    @DeleteMapping("/delete/{id}")
    public ResponseEntity<Result<Object>> deleteFeedback(@PathVariable int id) {
        try {
            service.deleteFeedback(id);
            return responseUtils.success(null, "删除成功");
        } catch (Exception e) {
            return responseUtils.fail(500, "删除失败：" + e.getMessage());
        }
    }
}